﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_GetStep]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_GetStep];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_GetStep]
    @FlowID int,
    @StepID int
AS
BEGIN
SET NOCOUNT ON;

IF @StepID > 0
BEGIN
    SELECT
            s.*,
            (
                SELECT COUNT(*) 
                FROM dbo.uds_flow_jump j
                WHERE j.flow_id= @flowid and j.step_id = s.step_id
            ) AS Jump_Count
        FROM 
            dbo.uds_flow_step s
        WHERE
            s.flow_id = @flowid
            and s.step_id = @stepid;
END
ELSE
BEGIN
    SELECT
            s.*,
            (
                SELECT COUNT(*) 
                FROM dbo.uds_flow_jump j
                WHERE j.flow_id= @flowid and j.step_id = s.step_id
            ) AS Jump_Count
        FROM 
            dbo.uds_flow_step s
        WHERE
            s.flow_id = @flowid
        ORDER BY
            s.step_id

END

END
GO